package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

type DevEventLog struct {
	ID        string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	RobotID   string `json:"robot_id" gorm:"column:robot_id;type:string;size:40;index:idx_createdAt_robotID,priority:2;comment:机器人id"`
	Level     int    `json:"level" gorm:"column:level;type:int;size:8;comment:级别"`
	Msg       string `json:"msg" gorm:"column:msg;type:string;size:200;comment:时间内容"`
	CreatedAt int64  `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;index:idx_createdAt_robotID,priority:1;comment:创建时间"`
}

// TableName 表名
func (d *DevEventLog) TableName() string {
	return "dev_event_log"
}

// BeforeCreate 自增id
func (d *DevEventLog) BeforeCreate(tx *gorm.DB) (err error) {
	if d.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	d.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &DevEventLog{})
}

type DevEventLogTpl struct {
	DevEventLog
}

func (DevEventLogTpl) TableName() string {
	return "dev_event_log_tpl"
}

func (DevEventLogTpl) Unimplemented() {

}
